package com.springboot.frame.excel.handler;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;

/**
 * @author madman
 */
public class StringCellHandler extends AbstractBaseCellHandler<String> {

  /**
   * String类型处理器接口
   */
  public static final StringCellHandler INSTANCE = new StringCellHandler();

  /**
   * Cell设值
   *
   * @param cell Cell对象
   * @param data 数据
   */
  @Override
  public void doWrite(Cell cell, String data) {
    if (StringUtils.isNotBlank(data)) {
      cell.setCellValue(data);
    }
  }

  /**
   * Cell读值
   *
   * @param cell Cell对象
   * @return Cell对象上的值
   */
  @Override
  public String read(Cell cell, Object object) {
    switch (cell.getCellTypeEnum()) {
      case NUMERIC:
        return String.valueOf(cell.getNumericCellValue());
      case STRING:
        return cell.getStringCellValue();
      case BOOLEAN:
        return String.valueOf(cell.getBooleanCellValue());
      default:
        return null;
    }
  }

}
